package com.xingzhengfan.eurekaclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestMQController {
    @Resource
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
    @Autowired
    private MQService mqService;

    @RequestMapping(value = "/financeSend", method = RequestMethod.GET)
    public String orderSend() {
        for (int i = 0; i < 5; ++i) {
            Map map = new HashMap();
            map.put("orderId", i);

            MQConfig info = new MQConfig();
            info.setExchange(QoConstants.FINANCE_EXCHANGE_NAME);
            info.setInfo(map);
            threadPoolTaskExecutor.execute(new MQThread(mqService, info));
        }
        return "OK!";
    }
    @RequestMapping(value = "/orderSend", method = RequestMethod.GET)
    public String financeSend() {
        for (int i = 0; i < 5; ++i) {
            Map map = new HashMap();
            map.put("orderId", i);

            MQConfig info = new MQConfig();
            info.setExchange(QoConstants.ORDER_EXCHANGE_NAME);
            info.setInfo(map);
            threadPoolTaskExecutor.execute(new MQThread(mqService, info));
        }
        return "OK!";
    }
}
